<template>
	<view class="bank-container">
		<pagehead  pagesPath="/pagesMain/user/user">银行卡</pagehead>
		<!-- <view class="bank-content">
			<view class="title">一、识别下图二维码，注册好账号</view>
			<init-image  v-for="(item, index) in content" :key="index" :src="imgShow(item.img_url)" mode="widthFix" 
			style="max-width: 100%;margin: auto;"/>
		</view> -->
		<view class="bank-content">
			<view class="title-box">
				<view class="title"> <text class="line"></text>绑定银行卡</view>
				<!-- <view v-if="userYsReal">
					<view v-if="userYsReal.sign_status !=1" class="btn" @tap.stop="goSing()">前往签约</view>
					<view v-if="userYsReal.sign_status !=1" class="btn" @tap.stop="querySignResult()">签约状态更新</view>
				</view> -->
			</view>
			<view class="bank-content-list" v-if="isShowPage">
				<view class="bank-item" v-for="(item, index) in bankList" :key="index">
					<view class="bank-content-msg">
						<view class="bank-content-head-msg">
							<view class="bank-icon"></view>
							<view class="bank-right">
								<view class="bank-name">
									{{ item.account_name }}
								</view>
								<view class="bank-no">
									{{ item.account.slice(0, 4) + '**** ****' + item.account.substr(-4) }}
								</view>
							</view>
						</view>
						<view class="btn" @tap.stop="confrimdelete(item.id)">删除</view>
					</view>
					<view class="bank-type">
						<!-- <view class="mo" @tap.stop="changeMo(item)">
							<image v-if="item.checked" :src="IMAGE_STATIC + '/images/radio-checked.png'" class="ico" mode="heightFix" />
							<image v-else :src="IMAGE_STATIC + '/images/radio.png'" class="ico" mode="heightFix" />
							默认结算卡
						</view> -->
					</view>
				</view>
				<view class="initNoData" v-if="bankList.length == 0">—暂无数据—</view>
			</view>
			<view class="submit" @tap.stop="addBank()">
				绑定银行卡
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			IMAGE_STATIC: this.$url.assetsPath, // 静态图片地址
			isShowPage: false,
			bankList: [
				// 	{
				// 	bankId: 1,
				// 	bankName: '招商银行',
				// 	type: '借记卡',
				// 	cardNo: '621456451515622',
				// 	checked:0,
				// }, {
				// 	bankId: 2,
				// 	bankName: '建设银行',
				// 	type: '借记卡',
				// 	cardNo: '621456451515622',
				// 	checked:1,
				// }, {
				// 	bankId: 3,
				// 	bankName: '邮政银行',
				// 	type: '借记卡',
				// 	cardNo: '621456451515622',
				// 	checked:0,
				// }, 
			],
			content:[],
			deletestatus: false,
			usermsg:{},
			userYsReal:'',
			singUrl:''
		}
	},
	onLoad(options) {
		this.getData()
	},
	onHide() {
		// 离开页面清除singUrl
		// uni.removeStorageSync('singUrl');
	},
	onShow() {
		this.init();
		this.getUserInfo();
		this.getUserYsReal()
		// this.querySignResult()
	},
	methods: {
		init() {
			this.getBankList();
		},
		getBankList() {
			let that = this;
			const data = {}
			that.$Ajax('/api/user/account/getUserAccountInfo', data, res => {
				this.isShowPage = true;
				if (res.success) {
					that.bankList = res.data.userAccountInfo;
				}
			}, err => { this.isShowPage = true; })
		},
		// 解除绑定
		confrimdelete(bankId) {
			let that = this;
			uni.showModal({
				title: '温馨提示',
				content: '你确定解除删除该银行卡？',
				success: function (res) {
					if (res.confirm) {
						let data={
							user_account_oper:'user_account_del',
							account_id:bankId
						}
						console.log('data',data)
						that.$Ajax('/api/user/account/updateUserAccount',data, res => {
							if (res.success) {
								that.$tools.toast('删除成功');
								that.getBankList();
							}
						}, err => { }, 'DELETE')
					}
				}
			})
		},
		addBank(){
			// if(this.bankList.length>=1){
			// 	return this.$tools.toast("只能绑定一张银行卡！");
			// }
			console.log('usermsg',this.usermsg)
			if(this.usermsg.real_name){
				this.$tools.jump('/pages/bank/addbank')
			}else{
				this.$tools.toastJump('请先实名','/pages/setup/editUserInfo')
			}
		},
		// 获取二维码图片
		getData() {
      const data = {
        img_type: '05'
      }
      this.$Ajax('/api/system/appImg/getAppImgList', data, res => {
        if (res.success) {
          this.content = res.data.appImgList
        }
      })
    },
		changeMo(item) {
			console.log(item.checked)
			this.bankList.forEach(key => {
				key.checked = 0
			});
			item.checked = item.checked == 1 ? 0 : 1
		},
		// 去签约
		goSing(){
			console.log('跳转')
			// #ifdef H5
			location.href = this.singUrl
			// window.open(this.singUrl)
			// #endif
			// #ifdef MP-WEIXIN
			uni.setStorageSync('singUrl',encodeURIComponent(this.singUrl))
			this.$tools.jump('/pages/service/service','','','/pages/bank/bank')
			// #endif
			// #ifdef APP-PLUS
			this.$tools.jump('/pages/service/service',this.singUrl,'','/pages/bank/bank')
			// #endif
		},
		// 查询易税实名信息
		getUserYsReal() {
			let that = this;
			that.$Ajax('/api/user/info/getUserYsReal', {}, res => {
				if(res.success){
					that.userYsReal =  res.data.userYsReal;
					// if(that.userYsReal){
					// 	this.applySignUrl()
					// }
					// console.log('userYsReal',that.userYsReal)
				}
			}, err => {})
		},
		//前往签约
		applySignUrl() {
			let that = this;
			that.$Ajax('/api/user/ysReal/applySignUrl', {}, res => {
				if(res.success){
					that.singUrl =  res.data;
					console.log('singUrl',that.singUrl)
				}
			}, err => {})
		},
		//签约状态查询
		querySignResult() {
			let that = this;
			that.$Ajax('/api/user/ysReal/querySignResult', {}, res => {
				if(res.success){
					// that.userYsReal =  res.data.userYsReal;
					// console.log('userYsReal',that.userYsReal)
				}
			}, err => {})
		},
	}
}
</script>

<style scoped lang="scss">
.bank-container {
	.add-bank-page {
		width: 100%;
		height: 80vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.add-bank-page-tips {
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #888B95;
		}
	}

	.delet-modal {
		width: 560rpx;
		height: 600rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 3rpx 6rpx 1rpx rgba(0, 0, 0, 0.16);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.delet-modal-image {
			width: 230rpx;
			height: 157rpx;
			background: url($uni-static-dir+'/userimage/delete-image.png') 100% no-repeat;
			background-size: 100% 100%;
		}

		.delet-modal-tips {
			font-size: 32rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #666666;
			margin-top: 48rpx;
			margin-bottom: 82rpx;
		}

		.delet-modal-btngroup {
			display: flex;
			align-items: center;

			.delet-modal-cancelbtn {
				width: 198rpx;
				height: 76rpx;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				border: 2rpx solid #707070;
				text-align: center;
				line-height: 76rpx;
				margin-right: 84rpx;
			}

			.delet-modal-confrimbtn {
				width: 198rpx;
				height: 76rpx;
				background: #AD2926;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				text-align: center;
				line-height: 76rpx;
			}
		}
	}

	.bank-content {
		width: 93.6%;
		margin: auto;
		background: #FFFFFF;
		margin-top: 32rpx;
		padding: 20rpx 18rpx;

		.title-box {
			@include flexBetween;
			.title {
				font-weight: 500;
				font-size: 28rpx;
				color: #000000;
				line-height: 44rpx;
			}

			.line {
				display: inline-block;
				vertical-align: middle;
				width: 4rpx;
				height: 32rpx;
				background: #AD2926;
				margin-right: 12rpx;
			}
			.btn{
				display: inline-block;
				margin-left: 20rpx;
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
				background: #AD2926;
				color: #fff;
				font-size: 28rpx;
			}
		}

		.bank-content-list {
			height: 100%;

			.bank-item {
				.bank-content-msg {
					width: 100%;
					height: 228rpx;
					margin: 30rpx auto;
					overflow: hidden;
					background: url($uni-static-dir+'/userimage/bank-infoBg.png') 100% no-repeat;
					background-size: 100% 100%;

					.bank-content-head-msg {
						display: flex;
						align-items: center;
						margin-top: 45rpx;
						margin-left: 40rpx;

						.bank-icon {
							width: 54rpx;
							height: 34rpx;
							background: url($uni-static-dir+'/userimage/pay-icon.png') 100% no-repeat;
							background-size: 100% 100%;
						}

						.bank-right {
							.bank-no {
								margin-top: 24rpx;
								font-size: 32rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;
							}

							.bank-name {
								font-size: 32rpx;
								font-family: PingFang SC-Regular, PingFang SC;
								font-weight: 400;
								color: #FFFFFF;
								margin-left: 20rpx;
							}
						}
					}

				}

				.bank-type {
					margin-top: 30rpx;
					font-size: 28rpx;
					color: #666666;
					@include flexBetween;
				}

				.ico {
					width: 36rpx;
					height: 36rpx;
					display: inline-block;
					vertical-align: middle;
					margin-right: 10rpx;
				}

				.btn {
					width: 172rpx;
					text-align: center;
					height: 60rpx;
					line-height: 60rpx;
					border-radius: 74rpx 74rpx 74rpx 74rpx;
					border: 2rpx solid #fff;
					color: #fff;
					float: right;
					margin-right: 30rpx;
				}
			}
		}

		.submit {
			height: 88rpx;
			line-height: 88rpx;
			background: #AD2926;
			border-radius: 74rpx;
			width: 82%;
			margin: 20rpx auto;
			text-align: center;
			color: #fff;
			font-size: 30rpx;
			margin-top: 60rpx;
		}


	}
}
</style>
